package com.wt.wechatTools.room;

import android.content.Context;

import androidx.room.Database;
import androidx.room.Room;
import androidx.room.RoomDatabase;

import com.wt.wechatTools.room.dao.ContactsDao;
import com.wt.wechatTools.room.dao.UserDao;
import com.wt.wechatTools.room.entity.ContactsEntity;
import com.wt.wechatTools.room.entity.UserEntity;
//singleton 只允许生成一个实例，database生成实例时比较耗费资源。
@Database(entities = {UserEntity.class, ContactsEntity.class},version = 1,exportSchema = false)
public abstract class WorkDatabase extends RoomDatabase {
    private static WorkDatabase INSTANCE;
    public static synchronized  WorkDatabase getDataBase(Context context)
    {
        if (INSTANCE == null)
        {
            INSTANCE = Room.databaseBuilder(context.getApplicationContext(),WorkDatabase.class,"work_database").build();
        }
        return INSTANCE;
    }
    public abstract UserDao getUserDao();
    public abstract ContactsDao getContactsDao();
}
